package com.pospi.xstore.ui.cash_ui;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.pospi.xstore.R;
import com.pospi.xstore.adapter.RestOrderAdapter;
import com.pospi.xstore.dao.OrderDao;
import com.pospi.xstore.dto.OrderDto;
import com.pospi.xstore.ui.base.BaseActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class RestOrderActivity extends BaseActivity {

    @Bind(R.id.lv_order)
    ListView lvOrder;

    private List<OrderDto> orderDtos;
    public static final String REST_ORDER = "restOrder";
    public static final String REST_SCAN = "scan";
    public static final String REST_Point = "point_select";


    private OrderDao orderDao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentLayout(R.layout.activity_rest_order);
        setTitle("挂单");
        ButterKnife.bind(this);
        orderDao = new OrderDao(getApplicationContext());

        orderDtos = orderDao.selectRestOrder();
        RestOrderAdapter adapter = new RestOrderAdapter(getApplicationContext(), orderDtos);
        lvOrder.setAdapter(adapter);
        lvOrder.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent;
                intent = new Intent(RestOrderActivity.this, ScanReceiptActivity.class);
//                Bundle bundle = new Bundle();
//                bundle.putSerializable(REST_ORDER, orderDtos.get(position));
                intent.putExtra("rest",orderDtos.get(position));
                startActivity(intent);
                Log.i("跳转之前", "NO" + orderDtos.get(position).getMaxNo() + "");

                boolean delete = orderDao.deleteRestOrderInfo(orderDtos.get(position).getMaxNo());
                Log.i("delete", delete + "");
                finish();
            }
        });

    }
}
